﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OODCRM.Common;
using System.Windows;

namespace OODCRM.ViewModel
{
    public static partial class NavigationModel
    {
        #region ViewModel

        /// <summary>
        /// ViewModel for SanPham navigation button
        /// </summary>
        /// <!-->>> Author: viettp-->
        public static NavigationItemData SanPham
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "SanPham";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/Technorati_32x32.png", UriKind.Relative),
                            Label = "Sản phẩm",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(SanPham_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }

        public static NavigationItemData ChienDich
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "ChienDich";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/earning32.png", UriKind.Relative),
                            Label = "Chiến dịch",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(ChienDich_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }
        /// <!-->>> Author: cyworld8x-->
        public static NavigationItemData ToChuc
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "ToChuc";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/Company_128.png", UriKind.Relative),
                            Label = "Tổ chức",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(ToChuc_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }
        public static NavigationItemData LienHe
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "LienHe";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/contact32.png", UriKind.Relative),
                            Label = "Liên hệ",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(LienHe_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }

        public static NavigationItemData CoHoi
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "CoHoi";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/CoHoi32.png", UriKind.Relative),
                            Label = "Cơ hội",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(CoHoi_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }

        public static NavigationItemData TinhHuong
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "TinhHuong";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/Stumbleupon_32x32.png", UriKind.Relative),
                            Label = "Tình huống",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(TinhHuong_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }

        public static NavigationItemData TiemNang
        {
            get
            {
                lock (_lockObject)
                {

                    string Str = "TiemNang";

                    if (!_dataCollection.ContainsKey(Str))
                    {
                        NavigationItemData item = new NavigationItemData()
                        {
                            Image = new Uri("/OODCRM;component/Images/Misterwong_32x32.png", UriKind.Relative),
                            Label = "Tiềm năng",
                            IsChecked = false,
                            Command = new DelegateCommand<bool?>(TiemNang_SetState),
                        };
                        _dataCollection[Str] = item;
                    }

                    return _dataCollection[Str];
                }
            }
        }


        

        private static MainWindow CRMWindow
        {
            get
            {
                if (Application.Current.Properties.Contains("MainWindowRef"))
                {
                    WeakReference crmWindow = Application.Current.Properties["MainWindowRef"] as WeakReference;
                    if (crmWindow != null)
                    {
                        return crmWindow.Target as MainWindow;
                    }
                }
                return null;
            }
        }

        #endregion ViewModel


        #region Handlers

        private static void SanPham_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.SanPham);
                main.SetState(parameter, Feature.SanPham);
            }
        }


        private static void ChienDich_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.ChienDich);
                main.SetState(parameter, Feature.ChienDich);
            }
        }
        private static void ToChuc_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.ToChuc);
                main.SetState(parameter, Feature.ToChuc);
            }
        }
        private static void LienHe_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.LienHe);
                main.SetState(parameter, Feature.LienHe);
            }
        }
        private static void TiemNang_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.TiemNang);
                main.SetState(parameter, Feature.TiemNang);
            }
        }
        private static void CoHoi_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.CoHoi);
                main.SetState(parameter, Feature.CoHoi);
            }
        }
        private static void TinhHuong_SetState(bool? parameter)
        {
            if (!parameter.HasValue) return;
            MainWindow main = CRMWindow;
            if (main != null)
            {
                RibbonModelHelper.SetState(parameter, Feature.TinhHuong);
                main.SetState(parameter, Feature.TinhHuong);
            }
        }
        


        #endregion Handlers


        private static void DefaultExecuted()
        {
        }

        private static bool DefaultCanExecute()
        {
            return true;
        }

        #region Data
        private static object _lockObject = new object();
        private static Dictionary<string, NavigationItemData> _dataCollection = new Dictionary<string, NavigationItemData>();

        // Store any data that doesn't inherit from ControlData
        private static Dictionary<string, object> _miscData = new Dictionary<string, object>();
        #endregion Data
    }
}
